const gulp = require('gulp')
const cssmin = require('gulp-cssmin')
const uglify = require('gulp-uglify')
// const babel = require('gulp-babel')
const htmlmin = require('gulp-htmlmin')

//转移文件不用开发依赖
const del =require('del')

//打包规则
function cssHandler() {
    return gulp
    .src('./src/css/*.css')
    .pipe(cssmin())
    .pipe(gulp.dest('./dist/css/'))
}
function jsHandler() {
    return gulp
    .src('./src/js/*.js')
    // .pipe(babel({ presets: [ '@babel/preset-env' ] })) //需要一个参数 就可以将ES6的语法转换成ES5的语法
    .pipe(uglify())
    .pipe(gulp.dest('./dist/js/'))
}
function htmlHandler () {
    return gulp
    .src('./src/views/*.html')
    .pipe(htmlmin())
    .pipe(gulp.dest('./dist/views'))
}

//转移jquery.swiper,image
function jqueryHandler (){
    return gulp
    .src('./src/jquery/**')
    .pipe(gulp.dest('./dist/jquery'))
}
function swiperHandler() {
    return gulp
    .src('./swiper/**')
    .pipe(gulp.dest('./dist/swiper'))
}
function imageHandler(){
    return gulp
    .src('./src/images/**')
    .pipe(gulp.dest('./dist/images'))
}
// 

//删除任务
function delHandler(){
    return del('./dist')
}


//创建一个默认任务

// const _default=gulp.parallel(cssHandler,jsHandler,htmlHandler,imageHandler,jqueryHandler,swiperHandler)
//逐个执行
const _default=gulp.series(
    delHandler,
    gulp.parallel(cssHandler,jsHandler,htmlHandler,imageHandler,jqueryHandler,swiperHandler)
)

//导出文件
module.exports = {
    cssHandler,
    jsHandler,
    htmlHandler,
    imageHandler,
    jqueryHandler,
    swiperHandler,
    delHandler,
    default:_default
}
